let initHomeList = {
  homeDate: '',
  homeList: {
    stories: [],
    top_stories: []
  },
  themes: {
    limit: null,
    others: [],
    subscribe: []
  },
  theme: {
    image: null,
    stories: []
  },
  newsBefore: null,
  homeMoreNewsStories: [],
  homeMoreNews: {},
  newsDetails: {},
  storyExtra: {},
  longComments: [],
  shortComments: [],
  shortCommentsBefore: null,
  shortCommentsMore: []
};

export function home(state = initHomeList, action) {
  switch (action.type) {
    case 'FETCH_HOME_LIST':
      return {
        ...state,
        title: '首页',
        homeDate: action.homeList.date,
        homeList: action.homeList
      };
    case 'FETCH_THEMES':
      return {
        ...state,
        themes: action.themes
      };
    case 'FETCH_THEME':
      return {
        ...state,
        theme: action.theme,
        newsBefore: action.theme.stories.length
          ? action.theme.stories[action.theme.stories.length - 1].id
          : null
      };
    case 'FETCH_NEWS_DETAILS':
      return {
        ...state,
        newsDetails: action.newsDetails
      };
    case 'FETCH_HOME_NEWS_MORE':
      return {
        ...state,
        homeDate: action.homeMoreNews.date,
        homeMoreNews: action.homeMoreNews
      };
    case 'FETCH_NEWS_MORE':
      return {
        ...state,
        moreNews: action.moreNews,
        newsBefore: action.moreNews.stories.length
          ? action.moreNews.stories[action.moreNews.stories.length - 1].id
          : null
      };
    case 'FETCH_STORY_EXTRA':
      return {
        ...state,
        storyExtra: action.storyExtra
      };
    case 'FETCH_LONG_COMMENTS':
      return {
        ...state,
        longComments: action.longComments.comments
      };
    case 'FETCH_SHORT_COMMENTS':
      return {
        ...state,
        shortComments: action.shortComments.comments,
        shortCommentsBefore: action.shortComments.comments.length
          ? action.shortComments.comments[
              action.shortComments.comments.length - 1
            ].id
          : null
      };
    case 'FETCH_SHORT_COMMENTS_MORE':
      return {
        ...state,
        shortCommentsMore: action.shortCommentsMore.comments,
        shortCommentsBefore: action.shortCommentsMore.comments.length
          ? action.shortCommentsMore.comments[
              action.shortCommentsMore.comments.length - 1
            ].id
          : null
      };
    default:
      return state;
  }
}
